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0 0 -1 0 0 -1 0 0 0 0 0 -1 1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 1 0 0 0 0 -1 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 ;
0 0 0 0 0 1 0 0 0 0 1 0 0 0 -1 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 -1 1 0 0 0 0 0 -1 0 ;
-1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 -1 0 0 0 0 1 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 -1 0 1 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 ;
];

p = 5;

g = 9.800;

x_fixed = [0.726
0.148
0.106
0.785
0.707
];

y_fixed = [0.339
0.837
0.407
0.120
0.972
];

m = [0.265
0.633
0.187
0.456
0.689
0.814
0.204
0.264
0.380
0.614
0.515
0.941
0.758
0.930
0.650
0.638
0.151
0.010
0.745
0.238
];

k_tot = 200;

% Mass x-coordinates for uniform stiffness allocation.
x_unif = [0.726
0.148
0.106
0.785
0.707
0.530
0.436
0.456
0.459
0.507
0.533
0.411
0.510
0.515
0.418
0.508
0.529
0.464
0.570
0.485
];

% Mass y-coordinates for uniform stiffness allocation.
y_unif = [0.339
0.837
0.407
0.120
0.972
-0.949
-0.351
-0.180
-0.465
-0.400
-0.165
-0.607
-0.815
-0.594
-0.714
-0.374
-0.501
-0.223
-0.628
-0.551
];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plotting code.

% The following code plots the tensile structure with evenly distributed
% stiffness.

k_unif = (k_tot/N)*ones(N,1);
ind_ex = find(k_unif < 1e-2); %do not show springs with k < 1e-2
Aadj = A(:,setdiff(1:N,ind_ex));
Aadj2 = double(Aadj*Aadj'-diag(diag(Aadj*Aadj')) ~= 0);
figure
gplot(Aadj2,[x_unif y_unif],'o-');
hold on
plot(x_fixed,y_fixed,'ro');
xlabel('x'); ylabel('y');
hold off

% Use the following code to plot your optimized structure.
% Here k_opt is the optimum stiffness profile and x_opt, y_opt the
% corresponding mass coordinates

%ind_ex = find(k_opt < 1e-2); %do not show springs with k < 1e-2
%Aadj = A(:,setdiff(1:N,ind_ex));
%Aadj2 = double(Aadj*Aadj'-diag(diag(Aadj*Aadj')) ~= 0);
%figure
%gplot(Aadj2,[x_opt y_opt],'o-');
%hold on
%plot(x_fixed,y_fixed,'ro');
%xlabel('x'); ylabel('y');
%hold off
